﻿using Gateway.Common.Entity;
using Gateway.Common.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Gateway.Domain.EFCore.Configuration
{
    public class EntityWithOperatorConfiguration<T> : EntityConfiguration<T> where T : EntityWithOperatorBase
    {
        public override void Configure(EntityTypeBuilder<T> builder)
        {
            base.Configure(builder);
            builder.Property(x => x.CreatedBy).IsRequired().HasMaxLength(50).HasComment("创建人");
            builder.Property(x => x.CreatorName).IsRequired().HasMaxLength(200).HasComment("创建人名称");
            builder.Property(x => x.CreatedTime).IsRequired().HasMaxLength(19).HasComment("创建时间").HasConversion(date => date.ToStandardString(), str => str.ToDateTime());
            builder.Property(x => x.LastModifiedBy).IsRequired().HasMaxLength(50).HasComment("最后修改人");
            builder.Property(x => x.LastModifierName).IsRequired().HasMaxLength(200).HasComment("修改人名称");
            builder.Property(x => x.LastModifiedTime).IsRequired().HasMaxLength(19).HasComment("最后修改时间").HasConversion(date => date.ToStandardString(), str => str.ToDateTime());
        }
    }
}